package com.taropan.wallpaper.ui;

import com.taropan.wallpaper.R;
import com.taropan.wallpaper.util.Consts;
import com.taropan.wallpaper.util.TextUtil;
import com.taropan.wallpaper.util.Utils;

import android.os.Bundle;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;
/**
 * @author taro
 * chyaohui@gmail.com
 * 2013-3-14下午11:34:59
 */
public class MainActivity extends TabActivity {
    protected static final String TAG = MainActivity.class.getSimpleName();
	/** Called when the activity is first created. */
	private static TabHost tabHost;
	private static Context context;
	private TextView main_tab_new_message;
	private static RadioButton main_tab_first;
	
	Intent mainPageIntent;
	Intent categoryIntent;
	Intent searchIntent;
	Intent managerIntent;
	 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        context=this;
        main_tab_new_message=(TextView) findViewById(R.id.main_tab_new_message);
        main_tab_new_message.setVisibility(View.VISIBLE);
        main_tab_new_message.setText("10");
        
        main_tab_first=(RadioButton) findViewById(R.id.main_tab_mainpage);
        
        tabHost=this.getTabHost();
        TabHost.TabSpec spec;
       
       
        mainPageIntent = new Intent(this, MainPageActivity.class);
        categoryIntent = new Intent(this,CategoryActivity.class);
        searchIntent = new Intent(this, SearchActivity.class);
        managerIntent = new Intent(this, ManagerActivity.class);
        tabHost.setCurrentTab(0);
        
        
    	setupIntent();
//		initRadios();
        
        RadioGroup radioGroup=(RadioGroup) this.findViewById(R.id.main_tab_group);
        radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.main_tab_mainpage://首页
					tabHost.setCurrentTabByTag(TextUtil.R("tab_mainpage"));
					Utils.dout(TAG, "main_tab_mainpage");
					break;
				case R.id.main_tab_category://分类
					Utils.dout(TAG, "main_tab_category");
					tabHost.setCurrentTabByTag(TextUtil.R("tab_category"));
					break;
				case R.id.main_tab_search://搜索
					Utils.dout(TAG, "main_tab_search");
					tabHost.setCurrentTabByTag(TextUtil.R("tab_search"));
					break;
				case R.id.main_tab_manager://管理
					Utils.dout(TAG, "main_tab_manager");
					tabHost.setCurrentTabByTag(TextUtil.R("tab_manager"));
					break;
				default:
					break;
				}
			}
		});
    }
    
    

//	/**
//	 * 初始化底部菜单
//	 */
//	private void initRadios() {
//		RadioButton radiobutton_flow = (RadioButton) findViewById(R.id.radiobutton_flow);
//		radiobutton_flow.setOnCheckedChangeListener(this);
//		radiobutton_flow.setChecked(true);
//
//		((RadioButton) findViewById(R.id.radiobutton_university))
//				.setOnCheckedChangeListener(this);
//
//		((RadioButton) findViewById(R.id.radiobutton_appraise))
//				.setOnCheckedChangeListener(this);
//
//		((RadioButton) findViewById(R.id.radiobutton_setting))
//				.setOnCheckedChangeListener(this);
//	}
	
	private void setupIntent(){
		MainActivity.tabHost = getTabHost();
		TabHost localTabHost = MainActivity.tabHost;
		localTabHost
				.addTab(buidTabSpec(getString(R.string.tab_mainpage),
						R.string.app_name, R.drawable.ic_launcher,
						this.mainPageIntent));

		localTabHost.addTab(buidTabSpec(getString(R.string.tab_category),
				R.string.app_name, R.drawable.ic_launcher,
				this.categoryIntent));

		localTabHost.addTab(buidTabSpec(getString(R.string.tab_search),
				R.string.app_name, R.drawable.ic_launcher,
				this.searchIntent));

		localTabHost
				.addTab(buidTabSpec(getString(R.string.tab_manager),
						R.string.app_name, R.drawable.ic_launcher,
						this.managerIntent));

		localTabHost.setCurrentTab(0);
	}
	
    
	private TabHost.TabSpec buidTabSpec(String tag, int resLabel, int resIcon,
			final Intent content) {
		return MainActivity.tabHost
				.newTabSpec(tag)
				.setIndicator(getString(resLabel),
						getResources().getDrawable(resIcon))
				.setContent(content);
	}
    
//    public static void changeTo(int id){
//    	
//    	tabHost.setCurrentTabByTag("tab_mainpage");
//    	Animation slideLeftIn = AnimationUtils.loadAnimation(context, R.anim.slide_left_in);
//    	tabHost.getCurrentView().startAnimation(slideLeftIn);
//    	main_tab_first.setChecked(true);
//    }
   
}
